package com.xm.servlet.reception_desk.pay;

import com.xm.entity.Address;
import com.xm.service.reception_desk.AccountInformationService;
import com.xm.service.reception_desk.AddressService;
import com.xm.service.reception_desk.OrdersService;
import com.xm.util.DecryptExampleUtil;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 支付页面
 * @author 康文程
 * @date 2023-12-23
 */
@WebServlet("/pay")
public class PayServlet extends HttpServlet {
    /**
     * 地址Service
     */
    private final AddressService addressService = new AddressService();
    /**
     * 账号Service
     */
    private final AccountInformationService accountInformationService = new AccountInformationService();
    /**
     * 订单Service
     */
    private final OrdersService ordersService = new OrdersService();

    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        //AES解密
        String informationId = DecryptExampleUtil.decrypt(req.getParameter("informationId"));
        System.out.println("---------");
        String orderId = req.getParameter("orderId");
        Address addressesByInformationIdAndSelected = addressService.
                getAddressesByInformationIdAndSelected(Integer.parseInt(informationId));
        //用户名称
        req.setAttribute("name",accountInformationService.getNameByInformationId(
                Integer.parseInt(informationId)));
        req.setAttribute("orderPrice",ordersService.getPaymentPriceByOrderId(orderId));
        req.setAttribute("orderId",orderId);
        req.setAttribute("accountId",req.getParameter("accountId"));
        req.setAttribute("address",addressesByInformationIdAndSelected);
        req.setAttribute("informationId",informationId);
        req.getRequestDispatcher("/WEB-INF/page/reception_desk/pay.jsp").forward(req, resp);
    }
}
